package com.desidea.common
{
	import mx.formatters.NumberFormatter;
	import mx.formatters.PhoneFormatter;
	
	public class CustomFormatter
	{
		private static var _instance:CustomFormatter;

		public function CustomFormatter(broker:SingletonBlocker):void
		{
		}
		
		public static function getInstance():CustomFormatter{
			if(_instance == null){
				_instance = new CustomFormatter(new SingletonBlocker());
			}
			return _instance;
		}

		public function converToNumberString(input:String, commaSeparator:Boolean=true):String{
			var cf:NumberFormatter = new NumberFormatter();
			cf.useThousandsSeparator = commaSeparator;
			return cf.format(input);
		}

		public function converToCurrencyString(input:String, commaSeparator:Boolean=true):String{
			var cf:NumberFormatter = new NumberFormatter();
			cf.useThousandsSeparator = commaSeparator;
			cf.precision = 2;
			return cf.format(input);
		}
		
		public function convertToPhoneString(input:String):String{
			var x:String = input;
			while(true){
				x = input;
				x = x.replace("(","").replace(")","").replace(" ","").replace("-","").replace("+","").replace(".","");
				if(x == input) 
					break;
				else
					input = x;
			}
			var pf:PhoneFormatter = new PhoneFormatter();
			return pf.format(input);
		}
	}
}

internal class SingletonBlocker {}